package cn.lger.icollege.controller;

import cn.lger.icollege.websocketEntity.UserChatCommand;
import org.springframework.messaging.handler.annotation.DestinationVariable;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.messaging.simp.annotation.SubscribeMapping;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;


@Controller
public class WSController {

    @Resource
    private SimpMessagingTemplate template;


    @MessageMapping("/userChat")
    public void userChat(UserChatCommand userChat){
        String dest="/userChat/chat"+userChat.getClassId();
        template.convertAndSend(dest,userChat);
    }



    @SubscribeMapping("/init/{classId}/{username}")
    public String userChat(@DestinationVariable("classId")int classId,@DestinationVariable("username")String username){
//        System.out.println("------------新用户进入，空间初始化---------");
        return "用户"+username+"加入聊天室";
    }
}
